//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================


//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LitwareHR.Recruiting.Contract;
using System.Threading;
using System.Globalization;
using LitwareHR.PublicApp.Presenters.Careers.Evaluation;

public partial class Careers_Evaluation_ResumeDetails : BasePage, IResumeDetailsView
{
    ResumeDetailsPresenter _presenter;

    public ResumeDetailsPresenter Presenter
    {
        get
        {
            return _presenter;
        }
    }

    protected override void OnInitComplete(EventArgs e)
    {
        base.OnInitComplete(e);
        _presenter = new ResumeDetailsPresenter(this);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        string resumeIdStr = Request.QueryString["resumeId"];

        if (string.IsNullOrEmpty(resumeIdStr) || 
            resumeIdStr.Length != 36 || resumeIdStr.Replace("-",String.Empty).Length != 32)
            throw new ArgumentNullException("resumeId");

        Guid resumeId = new Guid(resumeIdStr);

        string positionName = string.Empty;
        try
        {
            positionName = Request.QueryString["PositionName"];
        }
        catch
        {
            positionName = string.Empty;
        }

        _presenter.OnViewLoaded(resumeId, positionName);
    }

    public void ShowResumeDetails(Resume resume, string postionName)
    {
        this.ApplicantNameLiteral.Text = resume.ApplicantName;
        this.ApplicantSurnameLiteral.Text = resume.ApplicantLastName;
        this.AddressLiteral.Text = resume.Address;
        this.PhoneNumberLiteral.Text = resume.PhoneNumber;
        this.AdditionalInfoLiteral.Text = resume.AdditionalInfo;
        this.DateLiteral.Text = resume.Date.ToShortDateString();
        this.UserNameLiteral.Text = resume.Upn.UserName;
        this.PositionLiteral.Text = postionName;

        CustomDataGrid.DataSource = resume.Fields;
        CustomDataGrid.DataBind();
    }

    public void ShowSilverlightVideo(string silverLightAppName, string silverLightAccountId, VideoUploadState uploadState)
    {        
        this.ResumeVideoFieldset.Visible = true;
        this.CandidateVideoPanel.Visible = true;
        switch (uploadState)
        {
            case VideoUploadState.Available:
            {
                this.VideoPanel.Visible = true;
                string silverLightIFrame = "<iframe id=\"IFrame1\" src=\"http://silverlight.services.live.com/invoke/{0}/{1}/iframe.html\" frameborder=\"0\" width=\"248\" height=\"187\" scrolling=\"no\"></iframe>";
                this.silverLightIFrameLiteral.Text = String.Format(CultureInfo.InvariantCulture, silverLightIFrame, silverLightAccountId, silverLightAppName);        
                break;
            }
            case VideoUploadState.Uploading:
            {
                this.VideoUploadingProgressPanel.Visible = true;
                break;
            }
            case VideoUploadState.NoExists:
            {
                this.NoVideoPanel.Visible = true;
                break;
            }
            case VideoUploadState.Error:
            {
                this.ErrorVideoUploadingPanel.Visible = true;
                break;
            }
        }
    }
}
